#pragma once
#include<iostream>
#include<set>
#include<string>
using namespace std;

#define SSIZE 100000

#include<cstdlib>
#include<stdio.h>
#include<ctime>

void tTest_Set() {
	set<string> s;
	char buf[10];

	clock_t timeStart = clock();
	cout << "开始时间: " << timeStart << endl;

	for (int i = 0; i < SSIZE; i++) {
		try {
			snprintf(buf, 10, "%d", rand());
			s.insert(buf);
		}
		catch (exception& p) {
			cout << "i= " << i << " " << p.what() << endl;
			abort();
		}
	}

	cout << "set 赋值所需要时间: " << clock() - timeStart << endl;
	//因为有重复, 所以个数会小于定义的总数
	cout << "set 大小: " <<s.size() << endl;
	cout << "set 最大大小: " << s.max_size() << endl;

	string target;
	cin >> target;

	//使用标准库去查找元素
	timeStart = clock();
	multiset<string>::iterator pItem = ::find(s.begin(), s.end(), target);
	cout << "set 标准库find所需时间: " << clock() - timeStart << endl;
	if (pItem != s.end())
		cout << "找到元素: " << *pItem << endl;
	else
		cout << "找不到" << endl;


	//使用set自身的find查找元素
	timeStart = clock();
	pItem = s.find(target);
	cout << "set::find所需时间: " << clock() - timeStart << endl;
	if (pItem != s.end())
		cout << "找到元素: " << *pItem << endl;
	else
		cout << "找不到" << endl;
}